package com.sys.manage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sys.api.Controller.LoginController;
import com.sys.api.Service.ManagerLoginService;
import com.sys.api.Service.UserLoginService;
import com.sys.common.ZuelResult;
import com.sys.pojo.ManagerModel;
import com.sys.pojo.OrderUser;
import com.sys.vo.LoginVo;

import io.swagger.annotations.ApiOperation;

/**
 * 强哥快乐控制器。
 * @author 鸣濑白羽
 * @data 2021.4.1
 * */
@RestController
@RequestMapping("/manager")
public class LoginControllerImpl implements LoginController {

	
	@Autowired
	private ManagerLoginService managerLoginService;

	@Autowired
	private UserLoginService userService;
	
	@PostMapping("/login")
	@ApiOperation(value="强哥需要的统一登录接口",notes="who参数中0代表客服，1代表用户")
	@Override
	public ZuelResult Login(@RequestBody LoginVo vo) {
		// TODO Auto-generated method stub
		if (vo==null) {
			return ZuelResult.error(null, "请正确输入信息");
		}
		if (vo.getUserName()==null || vo.getUserName().equals(null)) {
			return ZuelResult.error(null, "请正确输入账号");
		}
		if (vo.getPasswords()==null || vo.getPasswords().equals(null)) {
			return ZuelResult.error(null, "请正确输入密码");
		}
		if (vo.getWho()!=null &&  vo.getWho().equals("0")) {
			ManagerModel model = new ManagerModel();
			model.setUsername(vo.getUserName());
			model.setPasswords(vo.getPasswords());
			return managerLoginService.ManagerLogin(model);
		}
		if (vo.getWho()!=null &&  vo.getWho().equals("1")) {
			//用户登录
			OrderUser user = new OrderUser();
			user.setUsername(vo.getUserName());
			user.setPasswords(vo.getPasswords());
			return userService.oderUserLogin(user);
		}else {
			return ZuelResult.error(null, "请正确输入身份信息");
		}
		
	}
	
	
}
